/**
 * 
 */
package com.bridgetree.jubaocrm.ui.groups;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.bridgetree.jubaocrm.R;
import com.bridgetree.jubaocrm.util.Projects;

/**
 * </p>
 * 客户二级页面 2014-5-20 上午11:21:00 create
 * 
 * @since 1.0
 */
public class GroupsContactListTwoActivity extends Activity {
	private final String TAG = "GroupMainListActivity";

	private Context mContext;

	private ListView group_main_list = null;

	private GroupsContactListTwoAdapter mGroupMainListAdapter = null;

	private Projects mProjects;

	private ArrayList<String> proInfoListData = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.group_main_list);
		mContext = this;

		Intent intent = getIntent();
		if(intent == null) {
			Log.e(TAG, "intent is null");
			return;
		}

		TextView xm_bi_tv_title = (TextView) findViewById(R.id.xm_bi_tv_title);
		
		if(intent.getExtras() != null) {
			mProjects = (Projects) intent.getExtras().getSerializable("groupsMain");
			xm_bi_tv_title.setText(mProjects.getProject_name());
		}

		findViewById(R.id.xm_bi_RelativeLayout_back).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});

		group_main_list = (ListView) findViewById(R.id.group_main_list);
		proInfoListData = new ArrayList<String>();
		proInfoListData.add("基本信息");
		proInfoListData.add("独占成员");
		proInfoListData.add("项目列表");
		proInfoListData.add("复审记录");

		mGroupMainListAdapter = new GroupsContactListTwoAdapter(mContext, proInfoListData);
		group_main_list.setAdapter(mGroupMainListAdapter);
		group_main_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				Intent intent;
				Bundle bundle;
				switch (arg2) {
					case 0:
						intent = new Intent(mContext, GroupsBasicInformationActivity.class);
						bundle = new Bundle();
						bundle.putSerializable("Projects", mProjects);
						intent.putExtras(bundle);
						startActivity(intent);
						break;
					case 1:
						intent = new Intent(mContext, GroupsContactMemberActivity.class);
						bundle = new Bundle();
						bundle.putSerializable("Projects", mProjects);
						intent.putExtras(bundle);
						startActivity(intent);
						break;
					case 2:
						intent = new Intent(mContext, GroupsProjectListTwoActivity.class);
						bundle = new Bundle();
						bundle.putSerializable("groupsMain", mProjects);
						intent.putExtras(bundle);
						startActivity(intent);
						break;
					case 3:
						intent = new Intent(mContext, GroupsFuShenActivity.class);
						bundle = new Bundle();
						bundle.putSerializable("Projects", mProjects);
						intent.putExtras(bundle);
						startActivity(intent);
						break;
				}
			}

		});
	}

	class GroupsContactListTwoAdapter extends BaseAdapter {
		private ArrayList<String> DrugstoreDataList = null;
		private LayoutInflater listContainer; // 视图容器

		private class GridHolder {
			ImageView xm_12_flag_iv;
			TextView tv;
		}

		public GroupsContactListTwoAdapter(Context mContext, ArrayList<String> data) {
			this.DrugstoreDataList = data;
			listContainer = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		}

		@Override
		public int getCount() {
			if(DrugstoreDataList != null) {
				return DrugstoreDataList.size();
			}
			return 0;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return DrugstoreDataList.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			GridHolder holder;
			if (convertView == null) {
				convertView = listContainer.inflate(R.layout.xm_12_my_item, null);
				holder = new GridHolder();
				holder.xm_12_flag_iv = (ImageView) convertView.findViewById(R.id.xm_12_flag_iv);
				holder.tv = (TextView) convertView.findViewById(R.id.xm_12_item_tv);
				convertView.setTag(holder);
			} else {
				holder = (GridHolder) convertView.getTag();
			}

			final String xm_txt=DrugstoreDataList.get(position);
			holder.tv.setText(xm_txt);
			holder.xm_12_flag_iv.setVisibility(View.VISIBLE);
			if(xm_txt.equals("基本信息")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_document);
			}else if(xm_txt.equals("独占成员")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_lock);
			}else if(xm_txt.equals("项目列表")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_list);
			}else if(xm_txt.equals("复审记录")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_checking);
			}
			return convertView;
		}

	}
}
